home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Discovering Windows 98
/
WinExpert9.iso
/
features
/
VisualBasic
/
Vb02
/
State after this tutorial
/
frmUnits.frm
(
.txt
)
next >
Wrap
Visual Basic Form
|
1997-12-03
|
4KB
|
133 lines
VERSION 5.00
Begin VB.Form frmUnits
Caption = "Units Conversion"
ClientHeight = 1485
ClientLeft = 60
ClientTop = 345
ClientWidth = 4065
LinkTopic = "Form1"
ScaleHeight = 1485
ScaleWidth = 4065
StartUpPosition = 3 'Windows Default
Begin VB.ComboBox cboConversionTypes
Height = 315
Left = 1560
Style = 2 'Dropdown List
TabIndex = 5
Top = 120
Width = 2415
End
Begin VB.CommandButton cmdConvert
Caption = "Convert"
Enabled = 0 'False
Height = 375
Left = 2640
TabIndex = 4
Top = 840
Width = 975
End
Begin VB.TextBox txtToUnits
Enabled = 0 'False
Height = 285
Left = 1080
TabIndex = 1
Top = 1080
Width = 855
End
Begin VB.TextBox txtFromUnits
Height = 285
Left = 1080
TabIndex = 0
Top = 720
Width = 855
End
Begin VB.Label Label1
Caption = "Conversion Type"
Height = 255
Left = 120
TabIndex = 6
Top = 120
Width = 1335
End
Begin VB.Label lblToUnits
Caption = "<To>"
Height = 255
Left = 120
TabIndex = 3
Top = 1080
Width = 975
End
Begin VB.Label lblFromUnits
Caption = "<From>"
Height = 255
Left = 120
TabIndex = 2
Top = 720
Width = 735
End
Attribute VB_Name = "frmUnits"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private mastrFromUnitNames(0 To 3) As String
Private mastrToUnitNames(0 To 3) As String
Private masngMultiplicationFactors(0 To 3) As Single
Private msngChosenFactor As Single
Private Sub cboConversionTypes_Click()
Dim intIndex As Integer
intIndex = cboConversionTypes.ListIndex
lblFromUnits = mastrFromUnitNames(intIndex)
txtFromUnits = ""
lblToUnits = mastrToUnitNames(intIndex)
txtToUnits = ""
msngChosenFactor = masngMultiplicationFactors(intIndex)
End Sub
Private Sub cmdConvert_Click()
txtToUnits = CStr(CSng(txtFromUnits) * msngChosenFactor)
End Sub
Private Sub Form_Load()
Dim intIndex As Integer
masngMultiplicationFactors(0) = 1.6093
mastrFromUnitNames(0) = "Miles"
mastrToUnitNames(0) = "Kilometres"
masngMultiplicationFactors(1) = 0.9144
mastrFromUnitNames(1) = "Yards"
mastrToUnitNames(1) = "Metres"
masngMultiplicationFactors(2) = 0.3048
mastrFromUnitNames(2) = "Feet"
mastrToUnitNames(2) = "Metres"
masngMultiplicationFactors(3) = 2.52
mastrFromUnitNames(3) = "Inches"
mastrToUnitNames(3) = "Centimetres"
For intIndex = 0 To 3
cboConversionTypes.AddItem mastrFromUnitNames(intIndex) & " to " & mastrToUnitNames(intIndex)
Next
'Pre-select list item number 0
cboConversionTypes.ListIndex = 0
End Sub
Private Sub txtFromUnits_Change()
If txtFromUnits.Text = "" Then
cmdConvert.Enabled = False
Else
cmdConvert.Enabled = True
End If
End Sub
Private Sub txtFromUnits_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) Then
If KeyAscii <> 8 Then
KeyAscii = 0
Beep
End If
End If
End Sub